#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    isStarted = false;

    timer = new QTimer;
    timeRecord = new QTime(0,0,0);

    ui->lcdNumber->setDigitCount(8);
    ui->pushButton->setText("Start");

    connect(timer, SIGNAL(timeout()),this, SLOT(updateTime()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    if(!isStarted)//timer not started
    {
        timer->start(1000);
        ui->pushButton->setText("Pause");
    }
    else
    {
        timer->stop();

        ui->pushButton->setText("Continue");
    }
    isStarted = !isStarted;
}

void MainWindow::on_pushButton_2_clicked()
{
    timer->stop();
    isStarted = false;
    timeRecord->setHMS(0,0,0);
    ui->lcdNumber->display(timeRecord->toString("hh:mm:ss"));
    ui->pushButton->setText("Start");
}
void MainWindow::updateTime()
{
    *timeRecord = timeRecord->addSecs(1);

    ui->lcdNumber->display(timeRecord->toString("hh:mm:ss"));
}








